import { _decorator, Component, Node } from 'cc';
import SUI, { show_dialog, show_hint, start_loading, show_wait } from '../../sgame/ui/SUI';
import { Prefab } from 'cc';
import { AssetBundle } from '../../sgame/resource/ResLoader';
import { EditBox } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('TestUI')
export class TestUI extends Component {
    private _ebHint: EditBox;
    private _ebDialog: EditBox;

    start() {
        this._ebHint = this.node.Component('ebHint', EditBox);
        this.node.OnClickChild("hint", () => {
            show_hint(this._ebHint.string);
        });

        this._ebDialog = this.node.Component('ebDialog', EditBox);
        this.node.OnClickChild("dialog", () => {
            show_dialog(this._ebDialog.string, () => {
                console.log("on confirm");
            }, () => {
                console.log("on cancel")
            }, "yes", 'no');
        });

        this.node.OnClickChild("wait", () => {
            let closeWait = show_wait(`等待中...`);
            this.scheduleOnce(closeWait, 10);
        });

        this.node.OnClickChild("loading", () => {
            start_loading('test_resource', (bundles: AssetBundle[]) => {
                let prefab = bundles[0].get("prefabs/test", Prefab);
                SUI.InitPrefab(prefab, SUI.GUIRoot);
            });
        });
    }
}